<div class="main">
	<form class="form-inline" role="form">
		<div class="form-group">
			<label> 通知列表: </label>
			<button type="button" class="btn btn-success" data-target="#addNoticeModal" data-toggle="modal"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;新建通知</button>
		</div>
	</form>
	<hr/>
	<table class="table table-striped table-hover" style="margin-top: 0px;word-break:break-all; word-wrap:break-all;">
		<thead>
			<colgroup>
			  <col>
			  <col width='60%'>
			  <col>
			  <col>
			  <col>
			</colgroup>
			<tr>
				<td>序号</td>
				<td>内容</td>
				<td>状态</td>
				<td>创建时间</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
            <#if response.empty>
			     <tr>
                    <td colspan="5"class="text-center" >
                    	暂无数据
                    </td>
                <tr>
			<#else>
				<#list response.result as notice>
					<tr>
						<td>${notice_index+1}</td>
						<td>${notice.content}</td>
						<td><#if notice.status == 0>无效<#else>有效</#if></td>
						<td>${notice.createDateFormat}</td>
						<td>
							<button type="button" class="btn btn-success" data-target="#updateNoticeModal${notice_index}" data-toggle="modal">修改</button>
							<button type="button" class="btn btn-warning" data-target="#deleteNoticeModal${notice_index}" data-toggle="modal"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
							<!-- 修改 -->
							<div id="updateNoticeModal${notice_index}" class="modal fade" tabindex="-1" data-width="400">
								<div class="modal-dialog">
									<div class="modal-content">
							
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title">修改通知</h4>
										</div>
							
										<div class="modal-body">
											<form class="form-horizontal form-bordered form-row-stripped" id="updateNoticForm${notice_index}">
												<div class="form-body">
													<div class="form-group">
														<label class="control-label col-md-3"> 内容: </label>
														<div class="col-md-5">
															<textarea type="text" name="content" rows="6" class="form-control">${notice.content}</textarea>
														</div>
													</div>
													<div class="form-group">
														<label class="control-label col-md-3"> 状态: </label>
														<div class="col-md-5">
															<select name="status"
																class="form-control select2_category">
																<option value="0" <#if notice.status == 0>selected="selected"</#if>>无效</option>
																<option value="1" <#if notice.status == 1>selected="selected"</#if>>有效</option>
															</select>
														</div>
													</div>
													<input type="hidden" name="id" value="${notice.id}" />
												</div>
											</form>
										</div>
										<div class="modal-footer">
											<button type="button" data-dismiss="modal" class="btn" >取消</button>
											<button type="button" class="btn btn-primary" id="updateNoticBtn${notice_index}" 
												onclick="saveOrUpdate('updateNoticForm${notice_index}', 'updateNoticBtn${notice_index}')">确定</button>
										</div>
									</div>
								</div>
							</div>
							<!-- 删除 -->
							<div id="deleteNoticeModal${notice_index}" class="modal fade" tabindex="-1" data-width="400">
								<div class="modal-dialog">
									<div class="modal-content">
							
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title">确定删除通知?</h4>
										</div>
										<div class="modal-body">
											<form class="form-horizontal form-bordered form-row-stripped">
												<div class="form-body">
													<div class="form-group">
														<label class="control-label col-md-3"> 序号: </label>
														<div class="col-md-5">
															<div class="form-control-static">${notice_index+1}</div>
														</div>
													</div>
													<div class="form-group">
														<label class="control-label col-md-3"> 内容: </label>
														<div class="col-md-5">
															<textarea type="text" name="content" rows="6" readonly="readonly" class="form-control">${notice.content}</textarea>
														</div>
													</div>
													<div class="form-group">
														<label class="control-label col-md-3"> 状态: </label>
														<div class="col-md-5">
															<select name="status" class="form-control select2_category" disabled="disabled">
																<option value="0" <#if notice.status == 0>selected="selected"</#if>>无效</option>
																<option value="1" <#if notice.status == 1>selected="selected"</#if>>有效</option>
															</select>
														</div>
													</div>
												</div>
											</form>
										</div>
										<div class="modal-footer">
											<button type="button" data-dismiss="modal" class="btn" >取消</button>
											<button type="button" id="deleteNoticBtn${notice_index}" class="btn btn-primary" onclick="deleteNotice(${notice.id}, 'deleteNoticBtn${notice_index}')">确定</button>
										</div>
									</div>
								</div>
							</div>
						</td>
					</tr>
				</#list>
			</#if>
		</tbody>
	</table>
</div>

<div id="addNoticeModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog">
		<div class="modal-content">

			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">新建通知</h4>
			</div>

			<div class="modal-body">
				<form class="form-horizontal form-bordered form-row-stripped" id="addNoticForm">
					<div class="form-body">
						<div class="form-group">
							<label class="control-label col-md-3"> 内容: </label>
							<div class="col-md-5">
								<textarea type="text" name="content"
									value="" rows="6" class="form-control"></textarea>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> 状态: </label>
							<div class="col-md-5">
								<select name="status"
									class="form-control select2_category">
									<option value="0" selected="selected">
												无效
											</option>
									<option value="1">
												有效
											</option>
								</select>
							</div>
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" data-dismiss="modal" class="btn" >取消</button>
				<button type="button" class="btn btn-primary" id="addNoticBtn" onclick="saveOrUpdate('addNoticForm', 'addNoticBtn')">确定</button>
			</div>
		</div>
	</div>
</div>
<script>
	function saveOrUpdate(formId, btnId){
		disable(btnId);
		$.post('${request.contextPath}/admin/notice/saveOrUpdate',
			$("#"+formId).serialize(),
	        function(data){
	            if(data.status == 200){
	            	disable(btnId);
					toastr.success("操作成功，系统将自动刷新");  
			        reload(3000);
			    }else{
			    	toastr.error("操作失败！"+data.message);  
			    	enable(btnId);
			    }
	        }, 'json');
	}
	
	function deleteNotice(id, btnId){
		disable(btnId);
		$.post('${request.contextPath}/admin/notice/delete/' + id,
	        function(data){
	            if(data.status == 200){
					toastr.success("操作成功，系统将自动刷新");  
					reload(3000);
			    }else{
			    	toastr.error("操作失败！"+data.message);  
			    	enable(btnId);
			    }
	        }, 'json');
	}
</script>
